﻿
using System.Text.RegularExpressions;

namespace ProjetoComperio.Framework.Util
{
    /// <summary>
    /// This class provides methods to validate information such as Email,CPF and CNPJ
    /// </summary>
    public static class Validation
    {
        /// <summary>
        /// This method validates an Email
        /// </summary>
        /// <param name="email">email address to validate</param>
        /// <returns>true is valid, false if not valid</returns>
        public static bool IsValidEmail(string email)
        {

            //regular expression pattern for valid email
            //addresses, allows for the following domains:
            //com,edu,info,gov,int,mil,net,org,biz,name,museum,coop,aero,pro,tv
            string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
    (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";

            Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);//Regular expression object
            //make sure an email address was provided
            if (string.IsNullOrEmpty(email))
                return false;


            return check.IsMatch(email);

        }
    }
}
